<?php

namespace SaTan\Dcat\EnvHelper\Http\Controllers;

use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Admin;
use Dcat\Admin\Show;
use Illuminate\Routing\Controller;
use SaTan\Dcat\EnvHelper\DcatEnvServiceProvider;
use SaTan\Dcat\EnvHelper\Http\Repositories\Env;

class DcatEnvController extends AdminController
{

    protected function trans($key, $replace = [], $locale = null)
    {
        return DcatEnvServiceProvider::trans($key, $replace, $locale);
    }

    protected function title()
    {
        return $this->trans('env.content.title'); // TODO: Change the autogenerated stub
    }

    protected function description()
    {
        return $this->trans('env.content.description'); // TODO: Change the autogenerated stub
    }


    protected function grid(): Grid
    {
        return Grid::make(new Env(), function (Grid $grid) {

            $grid->showFilter();
            $grid->showFilterButton();
            $grid->enableDialogCreate();

            $grid->name($this->trans('env.grid.name'))->label('success');
            $grid->value($this->trans('env.grid.value'))->label('info');
            $grid->notes($this->trans('env.grid.notes'))->label('dark');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('name', $this->trans('env.grid.name'));
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id): Show
    {
        return Show::make($id, new Env(), function (Show $show) {
            $show->field('name', $this->trans('env.grid.name'));
            $show->field('value', $this->trans('env.grid.value'));
            $show->field('notes', $this->trans('env.grid.notes'));
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form(): Form
    {
        return Form::make(new Env(), function (Form $form) {
            $form->text('name', $this->trans('env.grid.name'))->required();
            $form->textarea('value', $this->trans('env.grid.value'));
            $form->text('notes', $this->trans('env.grid.notes'));
        });
    }
}
